<?php 
class CProductlog extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;
	public function __construct()
	{
		$this->_name=R_PRE. "product_log";
		parent::__construct();
	}
	
	public function getList($type = '', $page = 1, $pageNum = 5, $uid = '', $ip = '')
	{
		$db = $this->getAdapter();
		$select = $db->select();
		$select->from($this->_name, array('*'))
			   ->limitPage($page, $pageNum);
		if ($type == 'uid') {
			$select->group('uid');
		} elseif ($type == 'ip') {
			$select->group('ip');
		}
		if ($uid) {
			$select->where('uid = ?', $uid);
		}
		if ($ip == '1') {
			$select->where('ip = ?', "''");
		} elseif (!empty($ip)) {
			$select->where('ip = ?', $ip);
		}
		$select->order('addtime desc');
		return $db->fetchAll($select);
	}

	public function getPageCount($type = '', $pageNum = 5, $uid = '', $ip = '') 
	{
		$db = $this->getAdapter();
		$select = $db->select();
		$select->from($this->_name, array('*'));
		if ($type == 'uid') {
			$select->group('uid');
		} elseif ($type == 'ip') {
			$select->group('ip');
		}
		if ($uid) {
			$select->where('uid = ?', $uid);
		}
		if ($ip == '1') {
			$select->where('ip = ?', "''");
		} elseif (!empty($ip)) {
			$select->where('ip = ?', $ip);
		}
		$select->order('addtime desc');
		$result = $db->fetchAll($select);
		return ceil(count($result)/$pageNum);
	}
}